export function getMinY(cards) {
  let min = cards[0].coords.y;
  for (let card of cards) {
    if (card.coords.y < min) {
      min = card.coords.y;
    }
  }
  return min;
}

export function generateColorById(str) {
  let id = str + ""
  let hash = 0;
  for (let i = 0; i < id.length; i++) {
    hash = id.charCodeAt(i) + ((hash << 5) - hash);
  }
  let color = '#' + Math.abs(hash).toString(16).padStart(6, 'f');
  return color;
}

export function getFrequentNumbers(ary, total) {
  let countObj = {};
  for (let num of ary) {
    if (countObj[num]) {
      countObj[num]++;
    } else {
      countObj[num] = 1;
    }
  }
  let result = [];
  for (let key in countObj) {
    if (countObj[key] >= total) {
      result.push(parseInt(key));
    }
  }
  return result;
}

export function sleep(timer) {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve();
    }, timer);
  })
}

export function groupArrayBySeven(ary) {
  let result = [];
  for (let i = 0; i < ary.length; i += 7) {
    result.push(ary.slice(i, i + 7));
  }
  return result;
}
